package com.jiliang.common.result;

/**
 * 错误码 枚举值
 *
 * @author xumqc
 * @version v_1.0.1
 * @since 2022/7/04 15:37
 */
public enum Errors {

    // 0-99 系统级
    SUCCESS("0", "success", "成功"),
    SYSTEM_ERROR("11", "system error", "系统错误"),
    SYSTEM_NO_ACCESS_ERROR("12", "system no access", "无权限访问"),
    SYSTEM_NO_AUTH_ERROR("13", "system no auth", "无权限操作"),
    SYSTEM_REQUEST_PARAM_ERROR("14", "system request param error", "请求参数错误"),
    SYSTEM_UPDATE_ERROR("15", "system update fail", "数据更新失败"),
    SYSTEM_INSERT_ERROR("16", "system insert fail", "数据插入失败"),
    SYSTEM_DELETE_ERROR("17", "system delete fail", "数据删除失败"),
    SYSTEM_DATA_ERROR("18", "system data exception", "数据异常"),
    SYSTEM_BUSINESS_ERROR("19", "system business", "系统繁忙,请您稍后再试"),
    SYSTEM_CONFIGURATION_ERROR("20", "system configuration error", "系统配置错误"),
    SYSTEM_HTTP_PARAM_ERROR("21", "system http param error", "HTTP参数错误"),
    SYSTEM_HTTP_RESULT_ERROR("22", "system http result error", "HTTP结果错误"),
    SYSTEM_DATA_CONVERT_ERROR("23", "system data convert error", "数据转换错误"),
    SYSTEM_CALL_INTERFACE_ERROR("24", "system call interface error", "调用接口失败"),
    SYSTEM_DATA_IS_DEL_ERROR("25", "system data is del error", "数据已经删除"),
    SYSTEM_UPDATE_NO_AUTH_ERROR("26", "system update no auth fail", "数据不允许更新"),
    SYSTEM_INSERT_NO_AUTH_ERROR("27", "system insert no auth fail", "数据不允许插入"),
    SYSTEM_DELETE_NO_AUTH_ERROR("28", "system delete no auth fail", "数据不允许删除"),
    SYSTEM_FILE_UPLOAD_FAIL("29","system file upload fail","上传文件失败"),
    SYSTEM_FILE_TOO_MAX_FAIL("30","system file too max fail","上传文件过大"),
    SYSTEM_FILE_TOO_MIN_FAIL("31","system file too min fail","上传文件过小"),
    SYSTEM_FILE_NULL_FAIL("32","system file null fail","上传文件为空"),
    SYSTEM_DATA_REPEAT_ERROR("33","system data repeat error","数据重复"),
    //验证
    VALIDATION_NOT_NULL("000001", "$1 is null", "$1必须不为空"),
    VALIDATION_NULL("000002", "$1 is not null", "$1必须为空"),
    VALIDATION_ASSERT_TRUE("000003", "$1 is not true", "$1必须为true"),
    VALIDATION_ASSERT_FALSE("000004", "$1 is not false", "$1必须为false"),
    VALIDATION_MIN("000005", "$1 less than $2", "$1必须大于等于$2"),
    VALIDATION_MAX("000006", "$1 greater than $2", "$1必须小于等于$2"),
    VALIDATION_DECIMAL_MIN("000007", "$1 less than $2", "$1必须大于等于$2"),
    VALIDATION_DECIMAL_MAX("000008", "$1 greater than $2", "$1必须小于等于$2"),
    VALIDATION_FUTURE("000009", "$1 less than now", "$1必须属于将来的日期"),
    VALIDATION_PAST("000010", "$1 greater than now", "$1必须属于过去的日期"),
    VALIDATION_SIZE("000011", "$1 size less $3 greater $4", "$1的$2必须在$3和$4之间"),
    VALIDATION_LENGTH("000012", "$1 length less $3 greater $4", "$1的$2必须在$3和$4之间"),
    VALIDATION_EMAIL("000013", "is not email", "不是有效的email地址"),
    VALIDATION_PATTERN("000014", "$1 is not $2", "$1不是正确的$2"),
    VALIDATION_VALID("000015", "$1 is error", "$1不正确");

    public String code;
    public String exception;
    public String msg;

    private Errors(String code, String exception, String msg) {
        this.code = code;
        this.exception = exception;
        this.msg = msg;
    }

    public static Errors getErrors(String code) {
        Errors result = null;
        for (Errors status : Errors.values()) {
            if (status.code.equals(code)) {
                result = status;
                break;
            }
        }
        return result;
    }

    public static void main(String[] args) {
        System.out.println(getErrors("0003333") == null);
    }

    /**
     * @param code
     * @return
     */
    public static String getMsg(String code) {
        String result = "";
        for (Errors status : Errors.values()) {
            if (status.code.equals(code)) {
                result = status.msg;
                break;
            }
        }
        return result;
    }

}
